<template>
  <button
    type="button"
    :disabled="disabled || loading"
    :class="[
      'w-fit flex items-center justify-center gap-2 cursor-pointer px-3 py-2.5 text-white text-sm font-medium rounded-lg transition-all whitespace-nowrap',
      !disabled && !loading
        ? 'bg-gradient-to-r from-amber-600 to-orange-600 hover:from-amber-700 hover:to-orange-700'
        : 'bg-gray-500 opacity-50 cursor-not-allowed',
    ]"
    @click="$emit('click')"
  >
    <div v-if="loading" class="loading-spinner"></div>
    <slot />
  </button>
</template>

<script setup lang="ts">
interface Props {
  loading?: boolean;
  disabled?: boolean;
}

withDefaults(defineProps<Props>(), {
  loading: false,
  disabled: false,
});

defineEmits<{
  click: [];
}>();
</script>

<style scoped>
.loading-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
</style>
